package com.wenzhoujie.library.customview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

public class SDImageCheckBox extends SDViewBase
{

	public ImageView mIvImage;
	private SDCheckBoxListener mListener;

	public SDImageCheckBox(Context context, AttributeSet attrs)
	{
		super(context, attrs);
		initView();
	}

	private void initView()
	{

		mIvImage = new ImageView(getContext());
		mIvImage.setScaleType(ScaleType.CENTER_INSIDE);
		this.addView(mIvImage, getLayoutParamsWW());
		this.setGravity(Gravity.CENTER);

		setCheckState(false);
		this.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				mSelected = !mSelected;
				setCheckState(mSelected);
				if (mListener != null)
				{
					mListener.onChecked(mSelected);
				}
			}
		});
	}

	public void setCheckState(boolean isChecked)
	{
		if (isChecked)
		{
			onSelected();
		} else
		{
			onNormal();
		}
	}

	@Override
	public void onNormal()
	{
		onNormalImageView(mIvImage);
		super.onNormal();
	}

	@Override
	public void onSelected()
	{
		onSelectedImageView(mIvImage);
		super.onSelected();
	}

	// ---------------------setter getter

	public void setmListener(SDCheckBoxListener mListener)
	{
		this.mListener = mListener;
	}

	public interface SDCheckBoxListener
	{
		public void onChecked(boolean isChecked);
	}

}
